'''
Created on Nov 25, 2010

@author: Polido
'''

import Angle
from time import time
from octorotor.joystick.JoystickData import JoystickFakeData

class DataPoint(object):
    '''
    classdocs
    '''
    
    def byteToAngle(self, byte):
        return byte / 255.0 * 360.0 
    
    def IsValid(self):
        return (self.Package[1] + self.Package[2] + self.Package[3]) & 0xFF == self.Package[8]
                

    def __init__(self, package, joystick):
        
        self.Package = package
        

        self.creationTime = time()
        self.Imu = Angle.Angle( 
                               self.byteToAngle(package[2]), 
                               self.byteToAngle(package[1]), 
                               self.byteToAngle(package[3]) )
        self.Joystick = joystick
        
        self.eStop = package[9]
        
        self.returnData = JoystickFakeData(
                                           package[5] / 255.0 * 2.0 - 1.0,
                                           package[6] / 255.0 * 2.0 - 1.0,
                                           package[7] / 255.0 * 2.0 - 1.0,
                                           package[4] / 255.0 * 2.0 - 1.0
                                           )